package com.example.touch_demo_master.base;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.touch_demo_master.common.CustomToast;

public abstract class BaseActivity extends AppCompatActivity {
   private static final int FAST_CLICK_INTERVAL = 500;//快速点击间隔
   private long lastClickTime;//last click time
   private CustomToast mToast;
   @Override
   protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//全局只能竖屏
      setContentView(getLayoutId());
      init();
   }

   public abstract int getLayoutId();

   public abstract void init();

   public void showToast(int id) {
      String ssdf = getString(id);
      showToast(ssdf);
   }

   public void showToast(String text) {
      if (!TextUtils.isEmpty(text)) {
         if (mToast == null) {
            mToast = new CustomToast(this);
         }
         mToast.setDuration(Toast.LENGTH_LONG);
         mToast.setText(text);
         mToast.show();
      }
   }

   /**
    * 判断是否是快速点击
    * @return
    */
   public boolean isFastClick() {
      long now = System.currentTimeMillis();
      if (now - lastClickTime < FAST_CLICK_INTERVAL) {
         return true;
      }
      lastClickTime = now;
      return false;
   }
}
